package com.ghck.shop.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;

import com.ghck.shop.model.MakerFlowWater;

public interface MakerFlowWaterMapper {

	@Insert("insert into t_maker_flow_water"
			+ "(maker_user_id,order_id,user_id,amount,create_time,update_time)"
			+ "values"
			+ "(#{makerUserId},#{orderId},#{userId},#{amount},now(),now())")
	@Options(useGeneratedKeys=true)
	public Integer addMakerFlowWater(MakerFlowWater makerFlowWater);
	
	
	@Select("select * from t_maker_flow_water where order_id=#{orderId}")
	public MakerFlowWater findMakerFlowWaterByOrderId(Integer orderId);
	
	@Update("update t_maker_flow_water set amount=amount+#{amount} where id=#{id}")
	public Integer updateMakerFlowWaterAmount(@Param("id")Integer id,@Param("amount")Integer amount);
	
	@Select("select * from t_maker_flow_water where maker_user_id=#{userId} and status=1 order by update_time desc limit #{start},#{limit}")
	public List<MakerFlowWater> listMakerPercentage(@Param("userId")Integer userId,@Param("start")Integer start,@Param("limit")Integer limit);
	
	@Select("select * from t_maker_flow_water where maker_user_id=#{userId} order by update_time desc limit #{start},#{limit} ")
	public List<MakerFlowWater> listMakerFlowWaters(@Param("userId")Integer userId,@Param("start")Integer start,@Param("limit")Integer limit);
	
	@Update("update t_maker_flow_water set status=1 where id=#{id}")
	public Integer updateMakerFlowWaterComplete(Integer id);
	
	@Select("select sum(amount) allMount from t_maker_flow_water where maker_user_id=#{userId} and status=1 and date_format(update_time,'%Y-%m')=date_format(now(),'%Y-%m')")
	public Integer monthPercentage(Integer userId);
	
	@Select("select sum(amount) allMount from t_maker_flow_water where maker_user_id=#{userId}  and status=1")
	public Integer allPercentage(Integer userId);
}
